<template>
	<view class="container">
		<view>
		</view>
		<view class="uni-padding-wrap">
			<uni-segmented-control :current="current" :values="items" :style-type="styleType"
				:active-color="activeColor" @clickItem="onClickItem" />
		</view>
		<view class="uni-list">
			<case-list-content :list-data="listData" :rows="rows">
				<template #patrolType="item">
					<view class="list-row" >
						<view class="list-row-label" >巡查类型</view>
						<view class="list-row-content" >{{dictMap.patrol_type[item.data.patrolType]}}</view>
					</view>
				</template>
				<template #status="item">
					<view class="list-row" >
						<view class="list-row-label" >任务状态</view>
						<view class="list-row-content" >{{dictMap.patrol_plan_status[item.data.patrolStatus]}}</view>
					</view>
				</template>
				<template #btns="item">
					<button class="common-btn primary-btn" v-if="current == '0'" size="mini"
						@click="handleDeal(item.data,'deal')">巡查录入</button>
					<button class="common-btn other-btn" v-else size="mini"
						@click="handleDeal(item.data,'view')">查看详情</button>
				</template>
			</case-list-content>
		</view>
		<uni-load-more :status="status" :icon-size="16" :content-text="contentText" />
	</view>
</template>

<script>
	import {
		getDicts
	} from "@/api/system/dict/data";
	import {
		dateUtils
	} from '@/utils/util.js';
	import {
		listPubPatrolTask
	} from "@/api/pub/pubPatrolTask";
	export default {
		dicts: ['patrol_type','patrol_plan_status'],
		data() {
			return {
				items: ['巡查任务', '我的录入'],
				current: 0,
				activeColor: '#2359C1',
				styleType: 'button',
				queryParams: {
					caseCode: "",
					reportTime: []
				},
				page: 1,
				size: 10,
				total: 0,
				listData: [],
				//列表显示字段
				rows: [{
					labelName: "计划名称",
					valueName: "planName"
				}, {
					labelName: "开始时间",
					valueName: "patrolStartTime"
				}, {
					labelName: "截止时间",
					valueName: "patrolEndTime"
				}, {
					labelName: "巡查类型",
					valueName: "patrolType",
					isSlot: true
				}, {
					labelName: "任务状态",
					valueName: "status",
					isSlot: true
				}],
				reload: false,
				status: 'noMore',
				adpid: '',
				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多'
				},
				sourceOptions: []
			}
		},
		methods: {
			onClickItem(e) {
				if (this.current !== e.currentIndex) {
					this.current = e.currentIndex
					this.getListData();
				}
			},
			getListData() {
				this.page = 1;
				this.reload = true;
				this.listData = [];
				console.log(JSON.stringify(this.queryParams));
				if (this.current == 0) {
					//待办
					this.getList();
				} else {
					//已办
					this.getDoneList();
				}
			},
			getList() {
				uni.showLoading({
					title: "加载中"
				})
				if (this.total && !this.reload) {
					//说明已有数据，目前处于上拉加载
					this.status = 'loading';
				}
				if (this.reload) {
					uni.stopPullDownRefresh();
				}
				this.queryParams.pageSize = this.size;
				this.queryParams.pageNum = this.page;
				this.queryParams.patrolObjType = "3";
				this.queryParams.patrolStatus = "1";
				//this.queryParams.isSupervise = "0";
				listPubPatrolTask(this.queryParams).then(res => {
					// console.log(JSON.stringify(res));
					uni.hideLoading();
					if (res.code == 200) {
						let list = res.rows;
						this.total = res.total;
						this.listData = this.reload ? list : this.listData.concat(list);
						this.reload = false;

					}
				})
			},
			getDoneList() {
				uni.showLoading({
					title: "加载中"
				})
				if (this.total && !this.reload) {
					//说明已有数据，目前处于上拉加载
					this.status = 'loading';
				}
				if (this.reload) {
					uni.stopPullDownRefresh();
				}
				this.queryParams.pageSize = this.size;
				this.queryParams.pageNum = this.page;
				this.queryParams.patrolObjType = "3";
				this.queryParams.patrolStatus = "2";
				listPubPatrolTask(this.queryParams).then(res => {
					console.log(JSON.stringify(res));
					uni.hideLoading();
					if (res.code == 200) {
						let list = res.rows;
						this.total = res.total;
						this.listData = this.reload ? list : this.listData.concat(list);
						this.reload = false;
					}
				})
			},
			handleQuery() {
				if (this.queryParams.reportTime && this.queryParams.reportTime.length > 0) {
					let params = {
						"rptTimeStart": this.queryParams.reportTime[0] + " 00:00:00",
						"rptTimeEnd": this.queryParams.reportTime[1] + " 23:59:59"
					}
					this.queryParams.params = params;
				}
				this.getListData();
				this.$refs.popup.close()
			},
			handleRepeat() {
				this.queryParams = {};
			},
			handleDeal(item, type) {
				console.log(JSON.stringify(item));
				// console.log(item.caseId);
				if (type == "deal") {
					uni.navigateTo({
						url: 'info?oper=deal&rowData=' + JSON.stringify(item)
					})
				} else {
					uni.navigateTo({
						url: 'info?oper=view&rowData=' + JSON.stringify(item)
					})
				}

			}
		},

		onLoad() {
			//问题来源
			getDicts("case_source").then(response => {
				this.sourceOptions = response.data;
			});

			this.page = 1;
			this.reload = true;
			this.listData = [];
			this.getList();
		},
		onNavigationBarButtonTap: function(e) {
			this.$refs.popup.open()
		},
		onPullDownRefresh() {
			this.getListData();
		},
		onReachBottom() {
			this.page++;
			if (this.listData.length < this.total) {
				this.status = 'more';
			} else {
				this.status = 'noMore';
				return;
			}
			if (this.current == 0) {
				//待办
				this.getList();
			} else {
				//已办
				this.getDoneList();
			}
		}
	}
</script>

<style lang="scss">
	.uni-padding-wrap {
		padding: 0px 10px;
	}

	.popup-content {
		padding: 15px;
		height: 500px;
		background-color: #fff;
	}

	.list-row {
		display: flex;
		padding-bottom: 10px;
	}

	.list-row-label {
		font-family: MicrosoftYaHei;
		font-size: 14px;
		font-weight: normal;
		line-height: 17px;
		letter-spacing: 0px;
		color: #9DA0AA;
		width: 25%;
	}

	.list-row-content {
		font-family: MicrosoftYaHei;
		font-size: 14px;
		font-weight: normal;
		line-height: 17px;
		letter-spacing: 0px;
		width: 75%;
		color: #353B50;
		white-space: nowrap;
		text-overflow: ellipsis;
		overflow: hidden;
	}

	.nav-btn {
		margin-right: 15px;
	}
</style>